
/*
 * BrushPanel.java
 *
 * Created on 2010-apr-26, 19:13:00
 */

package artistic;

/**
 *
 * @author Micke
 */
public class BrushPanel extends javax.swing.JPanel {

    /** Creates new form BrushPanel */
    public BrushPanel() {
        initComponents();
    }

    private ToolBox toolBox;

    public BrushPanel(ToolBox toolBox)
    {
        this.toolBox = toolBox;
        initComponents();
        size.setText(String.valueOf(brushSlider.getValue()));
        opacity.setText(String.valueOf(opacitySlider.getValue()));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        brushSlider = new javax.swing.JSlider();
        brushSizeLabel = new javax.swing.JLabel();
        size = new javax.swing.JLabel();
        opacitySlider = new javax.swing.JSlider();
        opacityLabel = new javax.swing.JLabel();
        opacity = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(artistic.ArtisticApp.class).getContext().getResourceMap(BrushPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setName("Form"); // NOI18N

        brushSlider.setBackground(resourceMap.getColor("brushSlider.background")); // NOI18N
        brushSlider.setForeground(resourceMap.getColor("brushSlider.foreground")); // NOI18N
        brushSlider.setValue(10);
        brushSlider.setName("brushSlider"); // NOI18N
        brushSlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                brushSliderStateChanged(evt);
            }
        });

        brushSizeLabel.setText(resourceMap.getString("brushSizeLabel.text")); // NOI18N
        brushSizeLabel.setName("brushSizeLabel"); // NOI18N

        size.setText(resourceMap.getString("size.text")); // NOI18N
        size.setName("size"); // NOI18N

        opacitySlider.setBackground(resourceMap.getColor("opacitySlider.background")); // NOI18N
        opacitySlider.setForeground(resourceMap.getColor("opacitySlider.foreground")); // NOI18N
        opacitySlider.setMaximum(255);
        opacitySlider.setValue(255);
        opacitySlider.setName("opacitySlider"); // NOI18N
        opacitySlider.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                opacitySliderStateChanged(evt);
            }
        });

        opacityLabel.setText(resourceMap.getString("opacityLabel.text")); // NOI18N
        opacityLabel.setName("opacityLabel"); // NOI18N

        opacity.setName("opacity"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(opacityLabel))
                    .addComponent(opacitySlider, 0, 0, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(opacity))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(brushSizeLabel))
                    .addComponent(brushSlider, 0, 0, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(size)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(brushSizeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(brushSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(size)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(opacityLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(opacitySlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(opacity)
                .addContainerGap(119, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void brushSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_brushSliderStateChanged
        Brush brush = toolBox.getActiveBrush();
        int value = brushSlider.getValue();
        brush.setSize(value, value);
        size.setText(String.valueOf(brushSlider.getValue()));
    }//GEN-LAST:event_brushSliderStateChanged

    private void opacitySliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_opacitySliderStateChanged
        int value = opacitySlider.getValue();
        opacity.setText(String.valueOf(value));
        toolBox.setOpacity(value);
    }//GEN-LAST:event_opacitySliderStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel brushSizeLabel;
    private javax.swing.JSlider brushSlider;
    private javax.swing.JLabel opacity;
    private javax.swing.JLabel opacityLabel;
    private javax.swing.JSlider opacitySlider;
    private javax.swing.JLabel size;
    // End of variables declaration//GEN-END:variables

}
